import JSONFieldHandler from "@/lib/field/core/JSONFieldHandler"
import BaseFieldClass from "@/lib/field/fieldClass/BaseFieldClass"
import fieldLoader from "@/lib/field/core/fieldLoader"
import FIELD_VALUE_TYPE from "@/lib/field/constants/commonConstants"
import JsonSeriType from "@/lib/field/base/JsonSeriType"



export default class BaseFlow extends BaseFieldClass{
	
	
	#title;
	#code;
	#leftPoiCode="_b_leftPoi";
	#topPoiCode="_b_topPoi";
	#flowNameCode="_b_flowName";
	#baseFieldGroup = [];
	// #seriType = new {
	// 		"type":"BaseFlow",
	// 		"page":"flow"
	// 	};
	
	constructor(title , code, fieldGroups){
		super();
		this.#title = title;
		this.#code = code;
		
		this.#baseFieldGroup = [];
		let fg = fieldLoader.createFieldGroup("基础属性","_b_group");
		fg.addField(fieldLoader.createField(FIELD_VALUE_TYPE.show.LABEL.code,"节点类型","_b_flowType", this.#title));
		let fnameField = fieldLoader.createField(FIELD_VALUE_TYPE.show.TEXT.code,"节点名称",this.#flowNameCode, this.#title);
		fnameField.value = this.#title;
		fg.addField(fnameField);
		fg.addField(fieldLoader.createField(FIELD_VALUE_TYPE.show.LABEL.code,"left坐标",this.#leftPoiCode, ""));
		fg.addField(fieldLoader.createField(FIELD_VALUE_TYPE.show.LABEL.code,"top坐标",this.#topPoiCode, ""));
		
		
		this.#baseFieldGroup.push(fg);
		
		if(fieldGroups){
			this.init(fieldGroups)
		}
		
	}
	init(fieldGroups){
		super.init({
			fieldGroups:[...this.#baseFieldGroup ,...fieldGroups]
		});
		return this;
	}
	
	genSeriObj(){
		let ret={
			"superSeriObj":super.genSeriObj(),
			"title":this.#title,
			"code":this.#code
		};
		return ret;
	
	}
	genProdObj(){
		let ret ={
			"title":this.#title,
			"code":this.#code
		}
		let allFields = super.getAllFields(); 
		for(let f of allFields){
			ret[f.code] = f.value || f.defaultValue;
		}
		return ret;
	}
	seriObj(obj){
		super.seriObj(obj.superSeriObj);
		this.#title =  obj.title;
		this.#code =  obj.code;
	}
	
	get title(){
		return this.#title;
	}
	set title(t){
		this.#title = t;
	}
	get code(){
		return this.#code;
	}
	set code(c){
		this.#code = c;
	}
	
	get type(){
		return "node";
	}
	
	get id(){
		return this.#code;
	}
	
	get left(){
		return super.getFieldValue(this.#leftPoiCode);
	}
	set left(c){
		super.setFieldValue(this.#leftPoiCode, c);
	}
	
	get top(){
		return super.getFieldValue(this.#topPoiCode);
	}
	set top(c){
		super.setFieldValue(this.#topPoiCode, c);
		
	}
	
	get name(){
		return super.getFieldValue(this.#flowNameCode);
	}
	
	set name(n){
		super.setFieldValue(this.#flowNameCode, n);
	}
	
	
	
}